iT邦幫忙

2025 iThome 鐵人賽

DAY 23
0
佛心分享-IT 人自學之術

LLM入門學習系列 第 23

Day 23:專案初始化與資料收集

  • 分享至 

  • xImage
  •  

Day 23:專案初始化與資料收集

一、學習目標與任務定義

本日學習重點在於為 FAQ 智能客服系統建立初始環境與知識資料庫,為後續的 RAG 系統開發奠定基礎。

任務目標 狀態
環境整備 建立清晰、可維護的專案資料夾結構。
資料收集 蒐集一組主題明確(Google 相關)的問答資料集。
結構化 CSV 結構化格式儲存,為後續向量化與檢索(RAG 架構)準備。

二、實作專案概述:RAG 智能客服系統

在最後七天我想要建構一個基於 Retrieval-Augmented Generation (RAG) 架構的智能客服系統。系統將結合知識檢索大型語言模型 (LLM),能夠從內部知識庫中檢索最相關的資訊,並生成精準、有依據的回答。

本日任務屬於專案的「資料準備與結構化」核心階段。


三、環境設定與專案結構設計

(1) 使用工具與套件

類別 工具/套件 目的
開發環境 Jupyter Notebook 程式碼撰寫與執行
核心處理 os, pathlib 專案資料夾建立與路徑管理
資料處理 pandas 結構化資料處理(CSV 檔案)
後續元件 FAISS, Sentence Transformers Day 24 向量化與檢索(RAG 核心)

(2) 專案結構設計

採用標準的 MLOps 專案結構,有效分離資料、程式邏輯與原始碼,確保專案的整潔與可維護性。

faq_chatbot/
├── data/
│   └── google_faq.csv        ← 知識庫問答資料集
├── notebook/
│   └── Day23_data_collection.ipynb
├── retriever.py              ← 檢索邏輯模組 (後續開發)
├── app.py                    ← 前端服務 (Gradio/Streamlit)
└── requirements.txt

四、資料收集與整理

(1) 資料主題與格式

  • 主題「Google 常見使用問題與解答」,涵蓋帳號、雲端硬碟、Gmail、地圖等使用疑問。
  • 資料量:共 20 條問答配對。
  • 格式:每筆資料包含 question(使用者詢問)和 answer(標準答案)。

(2) 資料建立程式(Python 實作)

在 Jupyter Notebook 中執行以下程式碼,完成資料夾建立與 CSV 檔案儲存。

import os
import pandas as pd

# 1. 建立資料夾
os.makedirs("faq_chatbot/data", exist_ok=True)

# 2. 問答資料集 (部分展示)
data = [
    ["如何建立 Google 帳號?", "前往 https://accounts.google.com/signup 填寫基本資料即可建立帳號。"],
    ["忘記 Gmail 密碼怎麼辦?", "到 https://accounts.google.com/signin/recovery 進行密碼重設。"],
    ["如何開啟 Google 雲端硬碟?", "登入帳號後至 https://drive.google.com/ 使用雲端硬碟。"],
    # ... 略 (完整 20 筆資料)
    ["如何刪除 Google 搜尋紀錄?", "前往 https://myactivity.google.com/ 點選刪除活動。"],
    ["Google Chrome 為什麼會當機?", "可能因擴充功能衝突或記憶體不足,建議更新重啟。"]
]

# 3. 轉為 DataFrame 並儲存
df = pd.DataFrame(data, columns=["question", "answer"])
df.to_csv("faq_chatbot/data/google_faq.csv", index=False, encoding="utf-8-sig")

print("✅ 已建立資料集,共", len(df), "筆問答。")

https://ithelp.ithome.com.tw/upload/images/20251007/20169488AGlo2ST6VE.png

(3) 資料驗證與檢查

from pathlib import Path

# 驗證檔案存在性
path = Path("faq_chatbot/data/google_faq.csv")
print("檔案存在?", path.exists())

# 隨機預覽資料
df_check = pd.read_csv("faq_chatbot/data/google_faq.csv", encoding="utf-8-sig")
print("\n隨機預覽 5 筆資料:")
print(df_check.sample(5))

https://ithelp.ithome.com.tw/upload/images/20251007/20169488oqiIh2eKc1.png

五、參考資料

  1. Hugging Face 官方文件:https://huggingface.co/docs
  2. FAISS 向量資料庫介紹:https://faiss.ai/
  3. Python 官方文件:https://docs.python.org/3/
  4. Google 支援中心:https://support.google.com/

本次題目使用大語言模型作為輔助


上一篇
Day 22:綜合回顧
下一篇
Day 24:建立知識向量資料庫 (Knowledge Vector Database)
系列文
LLM入門學習25
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言